Script for exporting ODE solution sol[[1]] as a keyframe sequence (Curve Table format)

(*Sequence parameters:*) 
filename="solution_keyframes"; 
time=5; (* animation time, sec ( = 0 for real-time solution playback ) *)
fps=25; (* = total number of keyframes if time is normalized (time = 1) *)


(*Keyframe resampling:*) 
Clear[t,ta];
t1t2=sol[[1,1,2,1,1]]; 
Δt=t1t2[[2]]-t1t2[[1]];(* solution time interval *)
vars=sol[[1,;;,1]]; (* phase variables *)

If[time==0,time=Δt];
tpb[t_]:= time*((t-t1t2[[1]])/(Δt)) (* playback time reparametrization function *)
rows=#[t]&/@Prepend[vars,tpb];(* exported functions (table rows) *)
Nframes=Ceiling[fps time]; (* total number of keyframes *)
tab=Table[rows/.sol[[1]],{t,t1t2[[1]],t1t2[[2]],Δt/Nframes}]; (* table of resampled values *)

(*Export to .csv:*) 
SetDirectory@NotebookDirectory[];
Export[filename<>".csv",Prepend[tab,ToString/@Prepend[vars,"time"]]\[Transpose]];